<!-- ROBOT007 于 2020/11/11 22:37 创建crash.vue 文件 -->
<template>
  <div class="app-container">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="异常名称:">
        <el-input v-model="formInline.name" clearable placeholder="异常名称" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <!--表格-->
    <el-table
      ref="singleTable"
      v-loading="loadstatus"
      :data="serverData"
      highlight-current-row
      empty-text="暂无数据"
      style="width: 100%"
    >

      <el-table-column
        property="name"
        label="异常名称"
      />

      <el-table-column
        property="creat_time"
        label="创建时间"
      />

      <el-table-column
        label="操作"
      >
        <template slot-scope="scope">
          <!--          <el-button @click="editFun(scope.row)" type="primary" size="mini">修改</el-button>-->
          <el-button type="danger" size="mini" @click="delFun(scope.row,0)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination
      background
      layout="total, prev, pager, next"
      :current-page="currentP"
      :page-size="formInline.size"
      :total="totals"
      @current-change="pageNext"
    />
  </div>
</template>

<script>
// import { findCrashByPage, findByPage } from '@/api/CrashHandlerApi'
import { findByPage, delCrash } from '@/api/CrashHandlerApi'

export default {
  name: 'Crash',
  data() {
    return {
      loadstatus: false,
      serverData: [],
      currentP: 1,
      totals: 0,
      formInline: {
        name: '',
        index: 1,
        size: 5
      }
    }
  },
  created() {
    this.initData()
  },
  methods: {
    delFun(data, type) {
      var ts = this
      this.$confirm('此操作将永久删除《' + data.name + '》异常信息吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var obj = {
          'id': data.id,
          'type': type
        }
        delCrash(obj).then(res => {
          var data = res.data
          if (data.code === '000000') {
            ts.$message.success(data.msg)
            ts.initData()
          } else {
            ts.$message.error(data.msg)
          }
        }).catch(error => {
          console.error('error', error)
        })
      }).catch(() => {
        console.error('取消')
      })
    },
    onSubmit() {
      this.formInline.index = 1
      this.initData()
    },
    pageNext(i) {
      this.formInline.index = i
      this.initData()
    },
    initData() {
      var ts = this
      // findCrashByPage(ts.formInline, res => {
      //   var data = res.data
      //   if (data.code === '000000') {
      //     ts.serverData = data.data.crashArr
      //     ts.totals = data.data.pages
      //     ts.currentP = ts.formInline.index
      //   }
      // }, error => {
      //   console.error(error)
      // })
      findByPage(ts.formInline).then(res => {
        var data = res.data
        if (data.code === '000000') {
          ts.serverData = data.data.crashArr
          ts.totals = ts.serverData.length > 0 ? data.data.pages : 0
          ts.currentP = ts.formInline.index
        }
      }).catch(error => {
        console.error('error', error)
      })
    }
  }
}
</script>

<style scoped>

</style>
